<template>
	<view class="container">
		<view>
			<desc-wrapper :title="title" :desc="desc"></desc-wrapper>
			<z-card>
				<view class="card-content-item">
					<text class="card-content-label_left">缘主姓名</text>
					<view class="card-content_right">
						<view class="input-name-box">
							<input class="input-item" v-model="form.name" type="text" placeholder="请输入姓名" />
						</view>
					</view>
				</view>

				<view class="card-content-item">
					<text class="card-content-label_left">缘主性别</text>
					<view class="card-content_right">
						<uni-data-checkbox selectedColor="#4e6542" selectedTextColor="#333" v-model="form.sex"
							:localdata="genders" @change="sexChange"></uni-data-checkbox>
					</view>
				</view>
				<view class="card-content-item">
					<text class="card-content-label_left">农历类型</text>
					<view class="card-content_right">
						<uni-data-checkbox selectedColor="#4e6542" selectedTextColor="#333" v-model="form.type"
							:localdata="calendar" @change="lunarChange"></uni-data-checkbox>
					</view>
				</view>
				<view class="card-content-item" style="width: 680rpx;">
					<text class="card-content-label_left" >出生日期</text>
					<view class="card-content_right flex-row flex-wrap flex-1" style="flex-wrap: nowrap;">
						<uni-data-select class="year" isCustomIndicator
							style="margin-right: 5rpx;margin-bottom: 5rpx;" :clear="false" v-model="form.year"
							:localdata="yearData" @change="yearChange"></uni-data-select>
						<uni-data-select class="time" isCustomIndicator
							style="margin-right: 5rpx;margin-bottom: 5rpx;" :clear="false" v-model="form.month"
							:localdata="monthData" @change="monthChange"></uni-data-select>
						<uni-data-select class="time" isCustomIndicator
							style="margin-right: 5rpx;margin-bottom: 5rpx;" :clear="false" v-model="form.day"
							:localdata="dayData" @change="dayChange"></uni-data-select>
						<uni-data-select class="time" style="margin-bottom: 5rpx;" isCustomIndicator :clear="false" v-model="form.hours"
							:localdata="hourData" @change="hourChange"></uni-data-select>
					</view>
				</view>

			</z-card>
			<view class="bottom-btns">
				<view class="start-btn" @click="onClick_1">
					<text class="">立即查询</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '童子命查询',
				desc: '测试方法：输入您的信息，点击立即查询，并查看查询结果，请自行体会其中的指示。',
				form: {
					name: '',
					sex: 0,
					type: 0,
					year: Number(new Date().getFullYear()),
					month: Number(new Date().getMonth()) + 1,
					day: Number(new Date().getDate()),
					hours: Number(new Date().getHours()),
					minute: 0
				},
				genders: [{
						value: 0,
						text: '男\b'
					},
					{
						value: 1,
						text: '女\b'
					}
				],
				calendar: [{
						value: 0,
						text: '农历'
					},
					{
						value: 1,
						text: '公历'
					}
				],
				yearData: [],
				monthData: [],
				dayData: [],
				hourData: [],
				fenData: [],
			};
		},
		onLoad() {
			for (let i = 1910; i <= 2023; i++) {
				this.yearData.push({
					value: i,
					text: i + '年'
				})
			}

			for (let i = 1; i <= 12; i++) {
				this.monthData.push({
					value: i,
					text: i + '月'
				})
			}

			for (let i = 1; i <= 30; i++) {
				this.dayData.push({
					value: i,
					text: i + '日'
				})
			}
			for (let i = 0; i <= 23; i++) {
				this.hourData.push({
					value: i,
					text: i + '时'
				})
			}
			for (let i = 0; i <= 59; i++) {
				this.fenData.push({
					value: i,
					text: i + '分'
				})
			}
		},
		methods: {
			yearChange() {},
			monthChange() {},
			dayChange() {},
			hourChange() {},
			fenChange() {},
			onClick_1() {
				let that = this;
				if (this.form.name == "") {
					uni.$u.toast("请输入姓名")
					return
				}
				uni.request({
					url: 'https://cs.appzdm.com:3000/Gongju/tongzi',
					method: 'POST',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: this.form,
					success: (res) => {
						console.log(res, '@@@@@@@');
						// debugger
						uni.navigateTo({
							url: `/pages/tongziming/detail?params=${JSON.stringify(res.data.data)}`
						})
					},
					fail: (error) => {
						console.error('Request Failed:', error);
					}
				});

			},
			onClick_2() {
				// alert(1);
			},
		},
	};
</script>
<style lang="scss">
	::v-deep .year .uni-select{
				width: 165rpx;
		    }
	::v-deep .time .uni-select{
			width: 115rpx;
			}
</style>